package com.mf.controller.basic;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mf.aspect.debounces.Debounce;
import com.mf.aspect.logApi.LogApi;
import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.basic.DtoSet;
import com.mf.entity.req.basic.ReqSet;
import com.mf.service.basic.ServiceSet;
import com.mf.entity.req.basic.search.SearchReqSet;

import java.util.List;

/**
 * Base-系统全局设置
 */
@RestController
@RequestMapping("set")
@SaCheckLogin
@Tag(name = "Base-系统全局设置")
@Debounce
public class ControllerSet {
    @Resource
    private ServiceSet serviceset;

    @Operation(summary = "分页列表查询")
    @SaCheckPermission("set:search")
    @PostMapping("/page")
    public Result<Page<DtoSet>> findPage(@RequestBody SearchReqSet searchReqSet) {
        return Result.success(serviceset.findPageByParams(searchReqSet));
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission("set:search")
    @PostMapping("/list")
    public Result<List<DtoSet>> list(@RequestBody SearchReqSet searchReqSet) {
        return Result.success(serviceset.findListByParams(searchReqSet));
    }

    @Operation(summary = "保存")
    @SaCheckPermission("set:edit")
    @LogApi("保存系统全局设置")
    @PostMapping("/save")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqSet reqSet) {
        serviceset.save(UtilConverter.converter(reqSet, DtoSet.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @LogApi("修改系统全局设置")
    @SaCheckPermission("set:edit")
    @PostMapping("/update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqSet reqSet) {
        serviceset.updateById(UtilConverter.converter(reqSet, DtoSet.class));
        return Result.success();
    }


    @Operation(summary = "删除")
    @LogApi("删除系统全局设置")
    @SaCheckPermission("set:delete")
    @GetMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) {
        serviceset.removeById(id);
        return Result.success();
    }
}
